$(document).ready(function () {

    //Language div's opening and closing codes.
    $(".languageMainLink").click(function (e) {
        if ($(".languageBoxMenuDiv").is(':hidden')) {
            $(".languageBoxMenuDiv").slideDown(200);
        }
        else {
            $(".languageBoxMenuDiv").slideUp(200);
        }
        $('body').one('click', function () {
            $(".languageBoxMenuDiv").slideUp(200);
        });
        e.stopPropagation();
    });
    //Language div's opening and closing codes.---END

    //Writing the selected language to language div header.
    $(".languageBoxMenuDiv div").click(function () {
        var spanValue = $(this).children("span").text()
        $("img.languageFlag").attr('src', $(this).children("img").attr('src'));
        $("span.languageSpan").text(spanValue);
    });
    //Writing the selected language to language div header.---END


    //MENU Hover and adjustments
    $(".menuMainHeader").hover(
	  function () {
	      $(this).prev("li").children("a").addClass("noBg");
	      $(this).children(".menuContent").show();
	      $(this).children(".menuMainHeaderLink").addClass("menuMainHeaderLinkHover");
	  },
	  function () {
	      $(this).prev("li").children("a").removeClass("noBg")
	      $(this).children(".menuContent").hide();
	      $(this).children(".menuMainHeaderLink").removeClass("menuMainHeaderLinkHover");
	  }
	);

    $(".menuFirstHeader a").hover(function () {
        $(this).children('img').attr("src", "/content/themes/default/img/menu/menuHomeHover.png");
    },
	  function () {
	      $(this).children('img').attr("src", "/content/themes/default/img/menu/menuHome.png");
	  }
	);
    $('.menuInnerContent').hide(); // Hide all divs
    $('.1_menuInnerContent').show(); // Show the first div
    $('.1_menuheader').addClass('menuInnerHeadersActive'); // Set the class for active state
    $('.menuInnerHeaders ul li a').hover(function () { // When link is clicked
        $(this).parents(".menuInnerHeaders").find("a").removeClass('menuInnerHeadersActive'); // Remove active class from links
        $(this).addClass('menuInnerHeadersActive'); //Set parent of clicked link class to active


        var currentTab = $(this).attr("class"); // Set currentTab to value of href attribute
        currentTab = currentTab.substring(0, currentTab.indexOf("_"));
        $(this).parents(".menuInnerHeaders").siblings('.menuInnerContent').hide(); // Hide all divs
        $(this).parents(".menuInnerHeaders").siblings("." + currentTab + "_menuInnerContent").show(); // Show div with id equal to variable currentTab
    });

    $('.menuInnerContent2').hide(); // Hide all divs
    $('.1_menuInnerContent2').show(); // Show the first div
    $('.1_menuheader2').addClass('menuInnerHeadersActive'); // Set the class for active state
    $('.menuInnerHeaders2 ul li a').hover(function () { // When link is clicked
        $(this).parents(".menuInnerHeaders2").find("a").removeClass('menuInnerHeadersActive'); // Remove active class from links
        $(this).addClass('menuInnerHeadersActive'); //Set parent of clicked link class to active


        var currentTab = $(this).attr("class"); // Set currentTab to value of href attribute
        currentTab = currentTab.substring(0, currentTab.indexOf("_"));
        $(this).parents(".menuInnerHeaders2").siblings('.menuInnerContent2').hide(); // Hide all divs
        $(this).parents(".menuInnerHeaders2").siblings("." + currentTab + "_menuInnerContent2").show(); // Show div with id equal to variable currentTab
    });


    //MENU Hover and adjustments ---END

    //branches 
    //	$(".branchesMapTopList ul li a").hover(
    //	  function () {
    //		var branchesTopCityDiv = $(this).parents("li").attr("class")
    //		branchesTopCityDiv = branchesTopCityDiv.substring(0, branchesTopCityDiv.indexOf("_"));
    //		$("." + branchesTopCityDiv + "_branchesMap").find(".branchesCityDivContent").stop(true, true).fadeIn();
    //	  }, 
    //	  function () {
    //		 var branchesTopCityDiv = $(this).parents("li").attr("class")
    //		branchesTopCityDiv = branchesTopCityDiv.substring(0, branchesTopCityDiv.indexOf("_"));
    //		$("." + branchesTopCityDiv + "_branchesMap").find(".branchesCityDivContent").stop(true, true).hide();
    //	  }
    //	);

    //	$(".branchesCityDiv a").hover(
    //	  function () {
    //		$(this).children(".branchesCityDivContent").stop(true, true).fadeIn();
    //	  }, 
    //	  function () {
    //		$(this).children(".branchesCityDivContent").hide();
    //	  }
    //	);

    $(".branchesMapTopList ul li a").live(
    {
        mouseenter: function () {

            var branchesTopCityDiv = $(this).parents("li").attr("class")
            branchesTopCityDiv = branchesTopCityDiv.substring(0, branchesTopCityDiv.indexOf("_"));
            $("." + branchesTopCityDiv + "_branchesMap").find(".branchesCityDivContent").stop(true, true).fadeIn();
        },
        mouseleave: function () {
            var branchesTopCityDiv = $(this).parents("li").attr("class")
            branchesTopCityDiv = branchesTopCityDiv.substring(0, branchesTopCityDiv.indexOf("_"));
            $("." + branchesTopCityDiv + "_branchesMap").find(".branchesCityDivContent").stop(true, true).hide();
        }
    });

    $(".branchesCityDiv a").live({
        mouseenter: function () {

            $(this).children(".branchesCityDivContent").stop(true, true).fadeIn();
        },
        mouseleave: function () {
            $(this).children(".branchesCityDivContent").hide();
        }
    });



    //branches tabs2
    $('.branchesTabContent').hide(); // Hide all divs
    $('.branchesTabContents .branchesTabContent:first').show(); // Show the first div
    $('.branchesTabsHeaders div:first').addClass('branchesTabsHeaderDivActive'); // Set the class for active state
    $('.branchesTabsHeaders div a').click(function () { // When link is clicked
        $('.branchesTabsHeaders div').removeClass('branchesTabsHeaderDivActive'); // Remove active class from links
        $(this).parent().addClass('branchesTabsHeaderDivActive'); //Set parent of clicked link class to active

        var currentTab = $(this).attr('href'); // Set currentTab to value of href attribute
        $('.branchesTabContent').hide(); // Hide all divs
        $(currentTab).show(); // Show div with id equal to variable currentTab
        return false;
    });
    //branches ---END


    //FAQ Content Boxs
    $(".faqContent:first").show();
    $(".faqDiv h2 a").click(function (e) {
        var faqContent = $(this).parents(".faqDiv").children(".faqContent");
        var faqOpenHideButton = $(this).parents(".faqDiv").children(".faqOpen_closeDiv").children("a");
        if (faqContent.is(":hidden")) {
            $(".faqContent").slideUp();
            $(".faqOpen_closeDiv a").removeClass("faqOpen_closeDivActive");
            $(".faqOpen_closeDiv a span").html("Answer");
            $(faqContent).slideDown();
            $(faqOpenHideButton).addClass("faqOpen_closeDivActive");
            $(faqOpenHideButton).children("span").html("Close");
        }
        else {
            $(faqContent).slideUp();
            $(faqOpenHideButton).removeClass("faqOpen_closeDivActive");
            $(faqOpenHideButton).children("span").html("Answer");
        }

    });

    $(".faqOpen_closeDiv a").click(function (e) {
        var faqContent = $(this).parents(".faqDiv").children(".faqContent");
        if (faqContent.is(":hidden")) {
            $(".faqContent").slideUp();
            $(".faqOpen_closeDiv a").removeClass("faqOpen_closeDivActive");
            $(".faqOpen_closeDiv a span").html("Answer");
            $(faqContent).slideDown();
            $(this).addClass("faqOpen_closeDivActive");
            $(this).children("span").html("Close");
        }
        else {
            $(faqContent).slideUp();
            $(this).removeClass("faqOpen_closeDivActive");
            $(this).children("span").html("Answer");
        }
    });
    //FAQ CONTENT BOXS END


    //Video iframe link copy
    $(".webinarTableDivBox4 a").click(function () {
        $(".webinarVideoDiv").html($(this).children(".webinarTableVideoCopy").html());
    })


    //E-Book Magnify Opacity
    $(".e-bookShadowMain").hover(
	  function () {
	      $(".eBookMagnify").stop(true, true).fadeTo("fast", 0.66);
	  },
	  function () {
	      $(".eBookMagnify").fadeTo("fast", 1);
	  }
	);

    //Trading_Central Opacity
    $(".tc_shadow").hover(
	  function () {
	      $(this).find(".zoom").stop(true, true).fadeTo("fast", 0.33);
	  },
	  function () {
	      $(".zoom").fadeTo("fast", 1);
	  }
	);

    //daily analysis tabs
    $('.analysisTabContent').hide(); // Hide all divs
    $('.analysisTabContent:first').show(); // Show the first div
    $('.analysisTab1_header a').addClass('selectedAnalysisHeader'); // Set the class for active state
    $('.dailyAnalysisTabHeaders li a').click(function () { // When link is clicked
        $('.dailyAnalysisTabHeaders li a').removeClass('selectedAnalysisHeader'); // Remove active class from links
        $(this).addClass('selectedAnalysisHeader'); //Set parent of clicked link class to active

        var currentAnalysisTab = $(this).parents("li").attr("class"); // Set currentTab to value of href attribute
        currentAnalysisTab = currentAnalysisTab.substring(0, currentAnalysisTab.indexOf("_"));
        $(".analysisTabContent").hide(); // Hide all divs
        $(".dailyAnalysisTabContents").find("." + currentAnalysisTab + "_content").show(); // Show div with id equal to variable currentTab
    });

    $(".loginMyGkfxBackgroundDiv").css("opacity", "0");
    $(".loginToMyGkfxButton").click(function () {
        $(".loginMyGkfxBackgroundDiv").slideDown(100);
        $(".loginMyGkfxBackgroundDiv").animate({ opacity: 1 }, 200, function () { });
        $(this).addClass("loginToMyGkfxButtonHover");
    });
    $(".loginMyGkfxClose").click(function () {
        $(".loginMyGkfxBackgroundDiv").animate({ opacity: 0 }, 100, function () { });
        $(".loginMyGkfxBackgroundDiv").slideUp(200);
        $(".loginToMyGkfxButton").removeClass("loginToMyGkfxButtonHover");
        $(".forgotPassword").fadeOut(200);
        $(".loginMyGkfx").fadeIn(200);

    });

    $(".loginMyGkfxForgotDetails").click(function () {
        $(".loginMyGkfx").fadeOut(200);
        $(".forgotPassword").fadeIn(200);
    });
    $(".tryToLoginAgainButton").click(function () {
        $(".forgotPassword").fadeOut(200);
        $(".loginMyGkfx").fadeIn(200);
    });

    $(".contentHeaderFollow").hover(function () {
        $(".contentHeaderFollowInnerDiv").show();
    },
	  function () {
	      $(".contentHeaderFollowInnerDiv").hide();
	  }
	);

    $(".contentHeaderShare").hover(function () {
        $(".contentHeaderShareInnerDiv").show();
    },
	  function () {
	      $(".contentHeaderShareInnerDiv").hide();
	  }
	);

    $(".leftSideBarTerms ul li a").click(function () {
        $(".leftSideBarTerms ul li a").removeClass("leftselected");
        $(this).addClass("leftselected");

    });



    $(".searchDiv .faqdivHeader h3").prepend("<span>&#8220;</span>");
    $(".searchDiv .faqdivHeader h3").append("<span>&#8221;</span>");
    $(".totalResults p").prepend("&#8220;");
    $(".totalResults p").append("&#8221;");

    $(".searchDiv .faqHeaderA").click(function (e) {
        var faqContent = $(this).parents(".searchDiv").children(".faqContent");
        var faqOpenHideButton = $(this).parents(".searchDiv").children(".faqOpen_closeDiv").children("a");
        if (faqContent.is(":hidden")) {
            $(".faqContent").slideUp();
            $(".faqOpen_closeDiv a").removeClass("faqOpen_closeDivActive");
            $(".faqOpen_closeDiv a span").html("See Results");
            $(faqContent).slideDown();
            $(faqOpenHideButton).addClass("faqOpen_closeDivActive");
            $(faqOpenHideButton).children("span").html("Close");
        }
        else {
            $(faqContent).slideUp();
            $(faqOpenHideButton).removeClass("faqOpen_closeDivActive");
            $(faqOpenHideButton).children("span").html("See Results");
        }

    });

    $(".searchDiv .faqOpen_closeDiv a").click(function (e) {
        var faqContent = $(this).parents(".searchDiv").children(".faqContent");
        if (faqContent.is(":hidden")) {
            $(".faqContent").slideUp();
            $(".faqOpen_closeDiv a").removeClass("faqOpen_closeDivActive");
            $(".faqOpen_closeDiv a span").html("See Results");
            $(faqContent).slideDown();
            $(this).addClass("faqOpen_closeDivActive");
            $(this).children("span").html("Close");
        }
        else {
            $(faqContent).slideUp();
            $(this).removeClass("faqOpen_closeDivActive");
            $(this).children("span").html("See Results");
        }
    });

    $(function () {
        $(".placeHolder").textPlaceholder();
    });

    $(".jquery-selectbox-moreButton").click(function () {
        $(".liveSelect").css("z-index", "10");
        $(this).parents(".liveSelect").css("z-index", "999999");
    });

    $(".tradingHoverTr").hover(
	  function () {
	      $(this).addClass("tradingHoverTrHover");
	      $(this).children("td").css("background-image", "none !important");
	  },
	  function () {
	      $(this).removeClass("tradingHoverTrHover");
	  }
	);

   
});
jQuery.fn.textPlaceholder = function () {

    return this.each(function () {

        var that = this;

        if (that.placeholder && 'placeholder' in document.createElement(that.tagName)) return;

        var placeholder = that.getAttribute('placeholder');
        var input = jQuery(that);

        if (that.value === '' || that.value == placeholder) {
            input.addClass('text-placeholder');
            that.value = placeholder;
        }

        input.focus(function () {
            if (input.hasClass('text-placeholder')) {
                this.value = '';
                input.removeClass('text-placeholder')
            }
        });

        input.blur(function () {
            if (this.value === '') {
                input.addClass('text-placeholder');
                this.value = placeholder;
            } else {
                input.removeClass('text-placeholder');
            }
        });

        that.form && jQuery(that.form).submit(function () {
            if (input.hasClass('text-placeholder')) {
                that.value = '';
            }
        });

    });

};